package cn.iocoder.yudao.module.system.dal.mysql.areaserve;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.areaserve.vo.IsHolidayPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.areaserve.vo.MdmEmployeePageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.areaserve.IsHolidayDO;
import cn.iocoder.yudao.module.system.dal.dataobject.areaserve.MdmEmployeeDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

@Mapper
public interface IsHolidayMapper extends BaseMapperX<IsHolidayDO> {
    default PageResult<IsHolidayDO> selectPage(IsHolidayPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IsHolidayDO>()
                .eqIfPresent(IsHolidayDO::getHolidayDate, convertToLocalDate(reqVO.getHolidayDate()))
                .orderByDesc(IsHolidayDO::getId));
    }

    default LocalDate convertToLocalDate(Date date) {
        if (date == null) {
            return null;
        }
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }
}
